package com.imooc.controller;

import com.imooc.controller.frontend.MainPageController;
import com.imooc.controller.superadmin.HeadLineOperationController;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2020/7/7-2020
 * @Description: 自定义servlet
 */
@WebServlet("/")
public class DispatcherServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取请求路径
        String requestPath = req.getServletPath();
        //获取请求方法
        String requestMethod = req.getMethod();
        //根据请求的路径以及请求的方法，分发到我们自定义的controller中进行处理
        if("/frontend/getmainpageinfo".equalsIgnoreCase(requestPath) && "get".equalsIgnoreCase(requestMethod)){
            new MainPageController().getMainPageInfo();
        }else if("/superadmin/addheadline".equalsIgnoreCase(requestPath) && "post".equalsIgnoreCase(requestMethod)){
            new HeadLineOperationController().addHeadLine(req,resp);
        }
    }
}
